package hotgammon.bot;

import hotgammon.domain.*;
import hotgammon.view.*;
import hotgammon.view.figures.*;
import hotgammon.view.tools.*;

import java.awt.event.MouseEvent;
import java.util.Iterator;
import java.util.List;

import minidraw.framework.*;
import minidraw.standard.*;

/** Tool to specifically to roll dices
 * 
 * Author Jim-Kyrre Benjaminsen
 */

public class BotStateTool extends NullTool implements StateTool  {
	private BackgammonUserInterface objectServer;
	private CheckerMoveTool checkerMoveTool;
	private BotMoveTool botMoveTool;
	private DieRollTool dieRollTool;

	public BotStateTool(BackgammonUserInterface ui) {
		this.objectServer = ui;

		checkerMoveTool = new CheckerMoveTool(objectServer);
		botMoveTool = new BotMoveTool(objectServer);
		dieRollTool = new DieRollTool(objectServer);
	}

	public void stateChange() {
		//Bot is red...Player is black

		if(objectServer.getGame().getPlayerInTurn() == Color.RED){ //Bot..............
			if(objectServer.getGame().getNumberOfMovesLeft() == 0){
				objectServer.getEditor().setTool(dieRollTool);
				objectServer.getEditor().showStatus("Throw the dice.");
			}else{
				objectServer.getEditor().setTool(botMoveTool);
				objectServer.getEditor().showStatus(
						"Player "+
						objectServer.getGame().getPlayerInTurn().toString()+
						": "+
						objectServer.getGame().getNumberOfMovesLeft()+
						" moves left"
				);
			}
		}else{ //Player............................
			if(objectServer.getGame().getPlayerInTurn() == null || objectServer.getGame().getNumberOfMovesLeft() == 0){
				objectServer.getEditor().setTool(dieRollTool);
				objectServer.getEditor().showStatus("Throw the dice.");
			}else{
				objectServer.getEditor().setTool(checkerMoveTool);
				objectServer.getEditor().showStatus(
						"Player "+
						objectServer.getGame().getPlayerInTurn().toString()+
						": "+
						objectServer.getGame().getNumberOfMovesLeft()+
						" moves left"
				);
			}
			if(objectServer.getGame().winner() != Color.NONE){
				objectServer.getEditor().setTool(new NullTool());
				objectServer.getEditor().showStatus(
						"GAME OVER : The Winner is "+
						objectServer.getGame().winner()
				);
			}
		}


	}

}
